"""
权限模型定义
实现RBAC权限控制的权限部分
"""
from tortoise import fields

from pkg.common.models.base_model import BaseModel


class Permission(BaseModel):
    """权限模型"""
    
    name = fields.CharField(max_length=100, description="权限名称")
    slug = fields.CharField(max_length=100, unique=True, description="权限标识")
    description = fields.TextField(null=True, description="权限描述")
    module = fields.CharField(max_length=50, description="所属模块")
    action = fields.CharField(max_length=50, description="权限动作")
    
    # 多对多关系将在relations.py中定义
    
    class Meta:
        table = "permissions"
        table_description = "权限表"
        app = "models"
        
    def __str__(self):
        return f"Permission(id={self.id}, name={self.name})"
        
    @property
    def full_name(self) -> str:
        """获取完整权限名称，格式为 module:action"""
        return f"{self.module}:{self.action}"
